﻿CREATE PROCEDURE [dbo].[CloseExistsDbConnection]
	@dbName NVARCHAR(200)
AS
BEGIN
	DECLARE @query varchar(2000)

	IF EXISTS(SELECT * FROM master.dbo.sysdatabases WHERE name = @dbName)
	BEGIN
		SET @query = 'ALTER DATABASE [' + @dbName + '] SET SINGLE_USER WITH ROLLBACK IMMEDIATE'
		EXEC (@query)
	END
END